package com.madvirus.review;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

public class ReviewCriteria extends Activity {

	private Spinner cuisine;
	private Button grabReviews;
	private EditText location;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.review_criteria);

		location = (EditText) findViewById(R.id.location);
		cuisine = (Spinner) findViewById(R.id.cuisine);
		grabReviews = (Button) findViewById(R.id.get_reviews_button);

		ArrayAdapter<String> cuisines = new ArrayAdapter<String>(this,
				R.layout.spinner_view, getResources().getStringArray(
						R.array.cuisines));

		cuisines.setDropDownViewResource(R.layout.spinner_view_dropdown);
		cuisine.setAdapter(cuisines);

		grabReviews.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				handleGetReviews();
			}
		});
	}

	private void handleGetReviews() {
		if ((location.getText() == null)
				|| location.getText().toString().equals("")) {
			new AlertDialog.Builder(this)
					.setTitle("Sorry")
					.setMessage("Location must be specified")
					.setPositiveButton("Continue",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int which) {
								}
							}).show();
			return;
		}
		RestaurantFinderApplication application = (RestaurantFinderApplication) getApplication();
		application.setReviewCriteriaCuisine(cuisine.getSelectedItem().toString());
		application.setReviewCriteriaLocation(location.getText().toString());
		Intent intent = new Intent(this, ReviewList.class);
		startActivity(intent);
	}
}